package com.mini.repository;

import com.mini.model.BusinessCooperativeBean;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 项目名称：traditional-business
 * 类 名 称：CooperativeRepository
 * 类 描 述：TODO
 * 创建时间：2020/12/3 上午10:55
 * 创 建 人：zhanghuiying
 */
@Repository
public interface CooperativeRepository extends JpaRepository<BusinessCooperativeBean,Long>, JpaSpecificationExecutor<BusinessCooperativeBean>
{
    List<BusinessCooperativeBean> findByQuantumArmyGroupIdAndThrowUserIdAndProjectIdAndAdChannelCodeAndThrowProvinceCode(Long quantumArmyGroupId, Long throwUserId, Integer projectId, String adChannelCode, String t);

    @Query(value = "SELECT count(*) FROM business_cooperative \n" +
            "WHERE cooperative_type != ?1\n" +
            "AND TO_DAYS(create_time)= TO_DAYS(?2) AND throw_user_id IN (?3) AND sell_apply_delete=1",nativeQuery = true)
    Integer findSellCount(Integer cooType,String now,List<Long> idList);

    @Query(value = "SELECT count(*) FROM business_cooperative \n" +
            "WHERE cooperative_type != ?1\n" +
            "AND TO_DAYS(create_time)= TO_DAYS(?2) AND quantum_army_group_id IN (?3) AND throw_apply_delete=1",nativeQuery = true)
    Integer findThrowCount(Integer cooType, String now, List<Long> idList);

    List<BusinessCooperativeBean> findByThrowUserIdAndProjectIdAndAdChannelCodeAndThrowProvinceCodeAndCooperativeState(Long userId, Integer projectId, String channelCode, String province, int i);
}